package com.jvyou.mybatis.spring.demo.utils;


import com.jvyou.mybatis.spring.demo.entity.User;

import java.util.Random;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/7/9 19:17
 * @Description 随机数据生成工具
 */
public class RandomDataUtil {
    private static final String[] boyNames = {"张三", "李四", "王五", "赵六", "陈七"};
    private static final String[] girlNames = {"小红", "小芳", "小翠", "小花", "小丽"};
    private static final String[] surnames = {"赵", "钱", "孙", "李", "周", "吴", "郑", "王"};
    private static final String[] emailDomains = {"gmail.com", "yahoo.com", "hotmail.com", "outlook.com"};

    private static final Random random = new Random();

    public static String generateRandomName() {
        boolean isMale = random.nextBoolean();
        String[] names = isMale ? boyNames : girlNames;

        // Generate a surname and a given name
        String surname = surnames[random.nextInt(surnames.length)];
        String givenName = names[random.nextInt(names.length)];

        return surname + givenName;
    }

    public static int generateRandomAge() {
        return random.nextInt(80) + 10; // Age between 10 and 89
    }

    /**
     * 生成随机英文数字邮箱
     *
     * @return 生成的随机邮箱
     */
    public static String generateRandomEmail() {
        // 生成随机用户名部分，这里简单使用随机字母和数字组合
        StringBuilder username = new StringBuilder();
        for (int i = 0; i < 5; i++) {
            int choice = random.nextInt(2);
            if (choice == 0) {
                // 随机字母
                char c = (char) ('a' + random.nextInt(26));
                username.append(c);
            } else {
                // 随机数字
                username.append(random.nextInt(10));
            }
        }
        int i = random.nextInt(emailDomains.length);
        return username + emailDomains[i];
    }

    public static User generateRandomUser() {
        return new User(generateRandomName(), generateRandomAge(), generateRandomEmail());
    }

}
